package cloudnative.demo.labclient.controller;

import cloudnative.demo.labclient.client.DeviceServiceClient;
import cloudnative.demo.labclient.model.Device;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@AllArgsConstructor
@RestController
@Slf4j
@RequestMapping("/device")
public class DeviceServiceClientController {
    @Autowired
    private final DeviceServiceClient deviceServiceClient;


    // 查询可用设备
    @GetMapping("/queryA")
    public List<Device> queryAvailableDevices() {
        return deviceServiceClient.queryAvailableDevices();
    }

    // 查询公共设备
    @GetMapping("/queryP")
    public List<Device> queryPublicDevices() {
        return deviceServiceClient.queryAllDevices();
    }

    // 查询所有设备
    @GetMapping("/queryAll")
    public List<Device> queryAllDevices() {
        return deviceServiceClient.queryAllDevices();
    }

    // 根据WorkerID、LaboratoryID查询设备
    @PostMapping("/queryM")
    public List<Device> queryDevicesByWorkerOrLab(@RequestBody Device device) {
        Long workerID = device.getWorkerID();
        Long laboratoryID = device.getLaboratoryID();
        return deviceServiceClient.queryAllDevices();
    }

    // 添加设备
    @PostMapping("/addD")
    public void addDevice(@RequestBody Device device) {
        deviceServiceClient.addDevice(device);
    }

    // 删除设备
    @PostMapping("/deleteD")
    public void deleteDevice(@RequestBody Device device) {
        deviceServiceClient.deleteDevice(device);
    }

    // 更新设备信息
    @PostMapping("/alterD")
    public void updateDevice(@RequestBody Device device) {
        deviceServiceClient.updateDevice(device);
    }

}
